package cn.tust.edu.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import  java.sql.Statement;
import java.util.*;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;


public class TestDriver {
public static void main(String[]args){
	jdbcConn();
	dbutilsConn();
}
private static void dbutilsConn() {
	try{
	QueryRunner qr=new QueryRunner(MyDataSource.getDataSource());
	String strSql ="select * FROM user1";
	List<Map<String,Object>> lst = qr.query(strSql, new MapListHandler());
	System.out.println(lst);
	}catch(Exception e){
		e.printStackTrace();
	}
}
private static void jdbcConn(){
	String strDbDriver="com.mysql.jdbc.Driver";
	String strDbUrl="jdbc:mysql://localhost:3306/user?useUnicode=true&amp;characterEncoding=UTF-8";
	String strUserName="root";
	String strUSerPsw="root";
	try{
		Class.forName(strDbDriver);
		Connection conn = DriverManager.getConnection(strDbUrl,strUserName,strUSerPsw);
		Statement st=conn.createStatement();
		String strSql="select * FROM user1";
		ResultSet rs=st.executeQuery(strSql);
		while(rs.next()){
			System.out.println("username:"+rs.getString("username"));
			System.out.println("userpsw:"+rs.getString("password"));
			System.out.println("------------------------");
		}
		rs.close();
		st.close();
	
		
	}catch(Exception e){
		e.printStackTrace();
	}
}
}
